//
//  CityTableViewController.m
//  Travel
//
//  Created by lanou3g on 15/12/8.
//  Copyright © 2015年 涂晓雨. All rights reserved.
//

#import "CityTableViewController.h"
#import "PlayDataHelper.h"
#import "CityModel.h"
#import "PlayTableViewController.h"
@interface CityTableViewController ()

@end

@implementation CityTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    //添加一个searchBar用于查询
//    UISearchBar *search = [[UISearchBar alloc]initWithFrame:CGRectMake(10, -40,self.view.frame.size.width - 100, 30)];
//    [self.view addSubview:search];
//    
//    //添加一个button
//    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width - 100 + 10 + 10, -40, self.view.frame.size.width - (self.view.frame.size.width - 100 + 10 + 10) - 10, 30)];
//    [button setTitle:@"取消" forState:UIControlStateNormal];
//    [self.view addSubview:button];
//    [button addTarget:self action:@selector(<#selector#>) forControlEvents:<#(UIControlEvents)#>]
//    
//    self.tableView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0);
    self.tableView.contentInset = UIEdgeInsetsMake(20,0, 0, 0);
    [self loadData];
}


-(void)loadData{
    
    [[PlayDataHelper sharePlayDataHelper] CityListData:self.tableView];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [PlayDataHelper sharePlayDataHelper].CityListArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" ];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    CityModel *city = [PlayDataHelper sharePlayDataHelper].CityListArray[indexPath.row];
    cell.textLabel.text = city.Name;
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CityModel *city = [PlayDataHelper sharePlayDataHelper].CityListArray[indexPath.row];
    [self.delegate cityName:city];
    [self.navigationController popToRootViewControllerAnimated:YES];
    [self dismissViewControllerAnimated:YES completion:nil];

}


@end
